package com.tz.colawallet.ui.activity;

import android.os.Build;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

import com.tz.colawallet.R;
import com.tz.colawallet.basecode.base.BaseActivity;
import com.tz.colawallet.constant.Key;

public class CommonWebViewActivity extends BaseActivity {

    WebView mCommonWebView;
    LinearLayout commonWebBack;

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_common_web_view;
    }

    @Override
    protected void init() {
        mCommonWebView = findViewById(R.id.common_web_view);
        commonWebBack = findViewById(R.id.common_web_back);
        commonWebBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

//        mCommonWebView = (WebView) findViewById(R.id.common_web_view);
        mCommonWebView.getSettings().setJavaScriptEnabled(true);
        mCommonWebView.getSettings().setBuiltInZoomControls(true);
        mCommonWebView.getSettings().setDisplayZoomControls(false);
        mCommonWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); //取消滚动条白边效果
//        mWebView.setWebChromeClient(webChromeClient);
//        mWebView.setWebViewClient(webViewClient);
        mCommonWebView.getSettings().setDefaultTextEncodingName("UTF-8");
        mCommonWebView.getSettings().setBlockNetworkImage(false);
        mCommonWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//自适应屏幕
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mCommonWebView.getSettings().setMixedContentMode(mCommonWebView.getSettings().MIXED_CONTENT_ALWAYS_ALLOW);  //注意安卓5.0以上的权限
        }
        mCommonWebView.setWebViewClient(new WebViewClient() {
            public boolean shouldOverrideUrlLoading(WebView view, String url) { //  重写此方法表明点击网页里面的链接还是在当前的webview里跳转，不跳到浏览器那边
                view.loadUrl(url);
                return true;
            }
        });

        mCommonWebView.loadUrl(getIntent().getStringExtra(Key.WEB_URL));
    }

    @Override
    protected void initTitle() {

    }

}
